<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Groups extends Admin_Controller
{
  private $module = 'users/groups';
  private $table = 'groups';

  function __construct()
  {
    parent::__construct();
    if ($this->uri->segment(3) != 'login') {
      if (!$this->session->userdata('userInfo')) {
        header('Location: ' . base_url(ADMIN_PATCH . '/users/login'));
        return false;
      }
    }
    $this->load->model('groups_model', 'model');
  }

  function index()
  {

    $data = array();
    $default_func = 'created';
    $default_sort = 'DESC';
    $data = array('module' => $this->module,
      'module_name' => 'Phân quyền',
      'default_func' => $default_func,
      'default_sort' => $default_sort
    );
    $this->twiggy->set($data, NULL, TRUE);
    $this->breadcrumbs->push($data['module_name'], ADMIN_PATCH . '/' . $this->module);
    $this->breadcrumbs->push('Danh sách', '/');
    $data['breadcrumbs'] = $this->breadcrumbs->show();
    $this->twiggy->title($data['module_name']);
    $this->twiggy->css('all', 'dashboard.css');
    $this->twiggy->js('script.js');
    $this->twiggy->template('groups/index')->display();
  }
  function ajaxLoadContent()
  {
    $this->load->library('AdminPagination');
    $config['total_rows'] = $this->model->getTotalsearchContent();
    $config['per_page'] = $this->input->post('per_page');
    $config['num_links'] = 3;
    $config['func_ajax'] = 'searchContent';
    $config['start'] = $this->input->post('start');
    $this->adminpagination->initialize($config);
    $result = $this->model->getsearchContent($config['per_page'], $this->input->post('start'));
    $data = array(
      'result' => $result,
      'per_page' => $this->input->post('per_page'),
      'start' => $this->input->post('start'),
      'module' => $this->module
    );
    $this->session->set_userdata('start', $this->input->post('start'));
    $this->twiggy->set($data, NULL, TRUE);
    $this->twiggy->template('groups/ajax_loadContent')->display();
  }
}